//
//  XMWaitPayOrderDetailViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/18.
//

#import "XMWaitPayOrderDetailViewController.h"
#import "XMWaitPayOrderView.h"
#import "XMNetwork+mine.h"
#import "XMPayViewController.h"

@interface XMWaitPayOrderDetailViewController ()<XMWaitPayOrderViewDelegate>

@property (nonatomic, strong) XMWaitPayOrderView *orderDetailView;

@end

@implementation XMWaitPayOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.orderDetailView];
    [self getOrderDetail];
}

- (void)getOrderDetail {
    XMWeakSelf;
    [_Network getOrderDetailWithOrderId:_orderId
                                success:^(id  _Nonnull responseObject) {
        XMOrderDetailModel *orderDetailModel = [XMOrderDetailModel yy_modelWithJSON:responseObject[@"data"]];
        [weakSelf.orderDetailView setContentWithOrderDetailModel:orderDetailModel];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

#pragma mark - Delegate
//取消订单
- (void)cancelOrderWithOrderId:(NSString *)orderId {
    XMWeakSelf;
    [_Network cancelMeetWithOrderId:orderId
                            success:^(id  _Nonnull responseObject) {
        weakSelf.editSuccessBlock ? weakSelf.editSuccessBlock() : nil;
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

- (void)contactWithPhone:(NSString *)phoneStr {
    NSString *urlStr = [NSString stringWithFormat:@"tel://%@", phoneStr];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlStr]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:^(BOOL success) {
            
        }];
    }
}

- (void)payActionWithOrderId:(NSString *)orderId
                       price:(NSString *)priceStr {
    XMPayViewController *payVC = [[XMPayViewController alloc] init];
    payVC.orderId = orderId;
    payVC.priceStr = priceStr;
    [self.navigationController pushViewController:payVC animated:YES];
}

#pragma mark - Init
- (XMWaitPayOrderView *)orderDetailView {
    if (!_orderDetailView) {
        _orderDetailView = [[XMWaitPayOrderView alloc] initWithFrame:self.view.bounds];
        _orderDetailView.delegate = self;
    }
    return _orderDetailView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
